home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_11
/
phillip2
/
cips4.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-22
|
42KB
|
1,574 lines
/***************************
*
* cips4.c
* COMPOSITE FILE COMPRISING:
* gin.c
* hist.c
* pi.c
* ht.c
*
***************************\
/*******************************************************
*
* file d:\cips\gin.c
*
* Functions: This file contains
* get_image_name
* get_directory_name
* extract_base_image_name
*
* Purpose - This function prompts the user to
* enter the name of an image.
*
* External Calls:
* clear_buffer
*
* Modifications:
* 26 September 86 - now uses vision3.h
* instead of vision2.h and the read_string
* and get_integer instead of scanf.
* 11 March 1987 - this function was
* removed from the file ip.c and put
* in file gin.c.
*
******************************************************/
#include "cips.h"
/*********************************************
*
* get_image_name(...
*
* This function reads in the desired image
* file name.
*
*********************************************/
get_image_name(name)
char name[];
{
char base_name[80],
dir_name[80],
new_name[80],
response[80];
int l;
printf("\n\nImage name is--%s\n", name);
printf("\nDo you want to change:");
printf("\n (f) file name");
printf("\n (d) directory name");
printf("\n (n) no change");
printf("\n _\b");
gets(response);
if((response[0] == 'F') ||
(response[0] == 'f')){
printf("\n\nEnter file name (name only no extension)");
printf("\n--");
gets(new_name);
extract_directory_name(name, dir_name);
sprintf(name, "%s%s.tif", dir_name, new_name);
}
if((response[0] == 'D') ||
(response[0] == 'd')){
printf("\n\nEnter directory name\n--");
gets(dir_name);
l = strlen(dir_name);
if(dir_name[l-1] != 47){
dir_name[l] = '/';
dir_name[l+1] = '\0';
}
printf("\n\nEnter file name (name only no extension)");
printf("\n--");
gets(new_name);
sprintf(name, "%s%s.tif", dir_name, new_name);
}
} /* ends get_image_name */
/*********************************************
*
* extract_directory_name(...
*
* This function extracts the sub-directory
* name out of a file name.
*
*********************************************/
extract_directory_name(file_name, dir_name)
char file_name[], dir_name[];
{
int i, j, k;
i = 1;
j = 0;
k = 0;
while(i){
if(file_name[k] == 47 ||
file_name[k] == 92) j = k;
if(file_name[k] == '\0') i = 0;
k++;
}
j++;
strncpy(dir_name, file_name, j);
dir_name[j] = '\0';
} /* ends extract_directory_name */
/*********************************************
*
* extract_base_image_name(...
*
* This function looks at a full file name
* and pulls off the sub-directory name and
* the file extension and returns the base
* file name.
*
*********************************************/
extract_base_file_name(file_name, base_name)
char base_name[], file_name[];
{
int i, j, k;
i = 1;
j = 0;
k = 0;
while(i){
if(file_name[k] == 47 ||
file_name[k] == 92) j = k;
if(file_name[k] == '\0') i = 0;
k++;
}
i = 1;
k = 0;
j++;
while(i){
if(file_name[j] == '.')
i = 0;
else
base_name[k] = file_name[j];
j++;
k++;
}
k--;
base_name[k] = '\0';
printf("\nEBN> base is %s", base_name);
} /* ends extract_base_file_name */
/**************************************************
*
* file d:\cips\hist.c
*
* Functions: This file contains
* calculate_histogram
* calculate_histogram
* zero_histogram
* perform_histogram_equalization
* show_histogram
* print_histogram
* smooth_histogram
* display_histogram
*
* Purpose: These functions calculate and display
* the histogram of an input image array.
*
* Modifications:
* July 86 - ported to IBM-PC
* August 1990 - modified for use in the
* C Image Processing System
* March 1992 - removed the hardwired values
* of 100 and replaced them with ROWS
* and COLS. There are still some
* hardwired numbers in this file, but
* they deal with displaying a histogram.
* October 4, 1992 - added the smooth histogram
* function.
*
**************************************************/
#define PRINT_WIDTH 80
#define FORMFEED '\014'
/*****************************************
*
* perform_histogram_equalization(...
*
* This function performs histogram
* equalization on the input image array.
*
******************************************/
perform_histogram_equalization(image, histogram,
new_grays, area)
float new_grays, area;
short image[ROWS][COLS];
unsigned long histogram[];
{
int i,
j,
k;
unsigned long sum,
sum_of_h[256];
double constant;
sum = 0;
for(i=0; i<256; i++){
sum = sum + histogram[i];
sum_of_h[i] = sum;
}
/* constant = new # of gray levels div by area */
constant = new_grays/area;
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
k = image[i][j];
image[i][j] = sum_of_h[k] * constant;
}
}
} /* ends perform_histogram_equalization */
/*****************************************
*
* zero_histogram(...
*
* This function clears or zeros a
* histogram array.
*
******************************************/
zero_histogram(histogram)
unsigned long histogram[];
{
int i;
for(i=0; i<=GRAY_LEVELS; i++)
histogram[i] = 0;
} /* ends zero_histogram */
/*****************************************
*
* calculate_histogram(...
*
* This function calculates the histogram
* for an input image arry.
*
******************************************/
calculate_histogram(image, histogram)
short image[ROWS][COLS];
unsigned long histogram[];
{
int i,j,k;
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
k = image[i][j];
histogram[k] = histogram[k] + 1;
}
}
} /* ends calculate_histogram */
/******************************************
*
* show_histogram(histogram)
*
* This function shows the histogram
* on the screen as numbers and stars.
*
*******************************************/
show_histogram(histogram)
unsigned long histogram[];
{
int count,
i,
j;
unsigned long max, scale;
max = 0;
count = 0;
for(i=0; i<GRAY_LEVELS; i++)
if(histogram[i] > max)
max = histogram[i];
if(max > (70 - 12))
scale = max/(70 - 12);
else
scale = 1;
printf("\n max=%ld scale=%ld",max, scale);
printf("\n\ngray count");
printf("\nlevel");
for(i=0; i<256; i++){
if(histogram[i] == 0)
++count;
else
count = 0;